package com.jy.appmarket.network.engine;

import java.io.UnsupportedEncodingException;
import java.util.Map;

import android.content.Context;
import android.os.Build;

import com.google.gson.Gson;
import com.jy.appmarket.model.UpdateModel;
import com.jy.appmarket.network.engine.cachestrategy.CacheStrategy;
import com.jy.appmarket.network.resultdata.AppUpdateResult;

public class AppUpdateNetEngine extends BaseNetEngine {
	private UpdateModel mUpdate;

	public AppUpdateNetEngine(UpdateModel um) {
		mUpdate = um;
		mResultData = new AppUpdateResult();
		mHttpMethod = HTTP_POSTBODY;
		setCacheStrategy(new CacheStrategy(false));
	}

	@Override
	protected String getCommand() {
		return "appupdate";
	}

	@Override
	protected void getParams(Context context, Map<String, String> params) {
		params.put("sdkVersion", String.valueOf(Build.VERSION.SDK_INT));
	}

	// @Override
	// protected void postParams(Context context, Map<String, String> params) {
	// Gson gson = new Gson();
	// String data = gson.toJson(mUpdate);
	// params.put("data", data);
	// }

	@Override
	protected String getContentType() {
		return "application/json";
	}

	@Override
	protected byte[] getBody(Context context) {
		Gson gson = new Gson();
		String data = gson.toJson(mUpdate);
		try {
			return data.getBytes("UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return null;
	}

}
